package com.cms.utils;

import com.cms.common.BeanFactory;
import com.cms.domain.Config;
import org.springframework.cache.CacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

/**
 * Utils - 缓存
 * 
 * 
 * 
 */
public class CacheUtils {

	/**
	 * 清除所有缓存
	 */
	public static void clearAll() {
		EhCacheCacheManager cacheCacheManager = (EhCacheCacheManager)BeanFactory.getBean(EhCacheCacheManager.class);
		cacheCacheManager.getCacheManager().clearAll();
		FreeMarkerViewResolver freeMarkerViewResolver = (FreeMarkerViewResolver)BeanFactory.getBean(FreeMarkerViewResolver.class);
		freeMarkerViewResolver.clearCache();
	}
	
	/**
	 * 清除config缓存
	 */
	public static void clearConfig(){
		EhCacheCacheManager cacheCacheManager = (EhCacheCacheManager)BeanFactory.getBean(EhCacheCacheManager.class);
		cacheCacheManager.getCacheManager().getCache(Config.CACHE_NAME).removeAll();
	}
}
